<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport"
	content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name='format-detection' content='telephone=no' />
<link rel="stylesheet" href="/assets/css/common.css" />
<link rel="stylesheet" href="/assets/css/iconfont/iconfont.css" />
<title>人车人</title><link rel="icon" href="/assets/img/titleico.ico" type="image/x-icon">
<script src="/assets/js/jquery-3.1.1.min.js"></script>
<style>
section .container .loginbox .username {
	border-bottom: 1px solid #eaeaea;
}

section .container .loginbox .password {
	border-bottom: 1px solid #eaeaea;
}

section .container .loginbox .yzm {
	position: relative;
}

section .container .loginbox .yzm img {
	position: absolute;
	top: .8rem;
	right: .8rem;
	width: 9rem;
	height: 2.4rem;
	border: 1px solid #ccc;
}

section .container .otherlogin {
	margin-top: 16%;
	display: none;
}

section .container .otherlogin p {
	color: #888;
	text-align: center;
	padding: .4rem 0 .8rem;
}

section .container .otherlogin ul li {
	text-align: center;
}

section .container .otherlogin ul li a {
	display: block;
}

section .container .otherlogin ul li i {
	color: #51b342;
	font-size: 2rem;
}

section .container .otherlogin ul li span {
	display: block;
	color: #333;
}
</style>
</head>
<body>
	<!-- header start -->
	#@loginHead("登录","
	<a href='/login/register'>注册</a>")
	<!-- end header -->
	<section id="login">
		<div class="container">
			<div class="logo">
<!-- 				<img src="/assets/img/logo.png" width="100%" title="人车人" alt="人车人" /> -->
			</div>
			<div class="loginbox">
				<form id="form">
					<div class="inputbox username">
						<input type="text" name="username" placeholder="手机号" />
					</div>
					<div class="inputbox password">
						<input type="password" name="password" placeholder="密码" />
					</div>
					<div class="inputbox yzm">
						<input id="vcode" type="text" name="vcode" placeholder="验证码" /> <img
							id="yzm" />
					</div>
				</form>
			</div>
			<div class="btnbox">
				<a href="javascript:;" id="btn" class="login fail">登录</a>
				<div class="flexbox">
					<a href="/login/register" class="reg sam">立即注册</a> <a
						href="/login/forget" class="sam fr">忘记密码？</a>
				</div>
			</div>
			<div class="otherlogin" style="display: none">
				<p>其它方式登录</p>
				<ul>
					<li><a href="#"> <i class="iconfont">&#xe604;</i> <span>微信</span>
					</a></li>
				</ul>
			</div>
		</div>
	</section>
</body>
<script src="/assets/js/fastclick.min.js"></script>
<script src="/assets/js/xxsg.js"></script>
<script>
	$(function(){
		var form = $("#form"),
			subbtn = $("#btn"),
			isSubmit = true;//控制是否可以点击登录
		subbtn.click(function(){
			if(isSubmit){
				isSubmit = false
				submit()
			}
		});
		
		getVcode()
		function getVcode(){
			$.ajax({
				type:"post",
				url:"/adminLogin/vcode",
				success:function(data){
					if(data.code!=0){
						#("yzm").src=data.path;
					}
				}
			})
		}
		$("#vcode").on("focus",function(){
			if (#("yzm").style.display=="none") {
				#("yzm").style.display="";
				getVcode();
			}
		})
		$("#yzm").on("click",function(){
			getVcode();
		})
		
		function submit(){
			var username = form[0].username.value,
				password = form[0].password.value,
				vcode = form[0].vcode.value;
			if(_x.isEmpty(username) || _x.isEmpty(password)){
				_x.showTip("请输入手机号或密码");
				isSubmit = true
				return false;
			}

			if(isNaN(username) || username.indexOf(".") != -1){
				_x.showTip("手机号格式不正确");
				isSubmit = true
				return false;
			}
			
			if(_x.isEmpty(vcode)){
				_x.showTip("请输入验证码");
				isSubmit = true
				return false;
			}

			var data = form.serialize();
			subbtn.html("<div class='textloading'></div>")
			$.ajax({
				type: "POST",
	            url: "/login/submit",
	            data: data,
	            success: function(data){
	            	if (data.code == 0) {
	               		_x.showTip(data.msg);
	               		subbtn.html("登录")
					}else{
						if(data.isFirstLogin){
							location.href = "/login/passwordReset";
						}else if(data.repeatLogin){
							alert("该账户已在其他设备登陆，如非本人操作，请尽快修改密码！")
							location.href = "/userCenter";
						}else{
							location.href = data.msg
						}
					}
	            	isSubmit = true
	            },
	            error:function(){
	            	subbtn.html("登录")
	            	isSubmit = true
	            	_x.showTip("网络出错，请稍后重试！")
	            }
			})
		};
		
		$(form[0].username).blur(blurYz);
		$(form[0].password).blur(blurYz);
		
		function blurYz(){
			var username = form[0].username.value,
				password = form[0].password.value;
			username = _x.trimAll(username);
			password = _x.trimAll(password);
			if(_x.isEmpty(username) || _x.isEmpty(password)){
				subbtn.addClass("fail");
				return false;
			}

			if(isNaN(username) || username.indexOf(".") != -1){
				subbtn.addClass("fail");
				return false;
			}
			subbtn.removeClass("fail");
		}
	})
</script>
</html>